<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : member.php   FILE_PATH : D:\webroot\mulitishop\member\member.php
 * ....会员管理会员资料
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 网城创想多用户商城开发团队 php_netproject@yahoo.com.cn
 * @package 
 * @subpackage 
 * @version Sat Aug 11 10:58:41 CST 2007
 */

require ("../global.inc.php");
class OwnMemberManage extends CommonFrameWork{
	/**
	 * 会员对象
	 *
	 * @var obj
	 */
	var $objmember;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $objvalidate;

	function main(){
		/**
		 * 创建会员对象
		 */
		if (!is_object($this->objmember)){
			require_once ("member.class.php");
			$this->objmember = new MemberClass();
		}
		
		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("member");

		/**
		 * 语言包
		 */
		$this->getlang("member");

		//用户管理界面上的菜单
		$this->memberMenuModule();
		
		/**
		 * 执行操作
		 */
		switch($this->_input['action']){
			case "modifysave":
				$this->_modifyBaseInfo();
				break;
			case "email":
				$this->output('InfoSelectorTarget',Common::getTargetMenu("member"));
				$this->_getMemberEmail();
				break;
			case "emailsave":
				$this->_saveMemberEmail();
				break;
			case "password":
				$this->output('InfoSelectorTarget',Common::getTargetMenu("member"));
				$this->showpage("own_member.password");
				break;
			case "passwordsave":
				$this->_saveMemberPassword();
				break;
			default:
				$this->output('InfoSelectorTarget',Common::getTargetMenu("member"));
				$this->_getBaseInfo();
				break;
		}

	}

	/**
	 * 得到会员的基本信息
	 *
	 */
	function _getBaseInfo(){
		/**
		 * 得到会员资料
		 */
		$condition['id'] = $_SESSION['s_login']['id'];
		$member_array = $this->objmember->getMemberInfo($condition,'*',$operate_genre='more');
		$this->output('member_array',$member_array);
		/*
		if (is_array($member_array)){
		foreach($this->objmember->getMemberInfo($_SESSION['s_mid']) as $k=>$v){
		$this->output($k,$v);
		}
		}
		*/
		/**
		 * 性别单选框
		 * 默认选中男性
		 */
		if ($member_array['gender']==""){
			$member_array['gender'] = "m";
		}
		$this->output("gender" , Common::showForm_Radio("rdoGender","",$this->_b_config['gender'],$member_array['gender']));
		$this->showpage("own_member.modi");
	}

	/**
	 * 修改会员基本资料
	 *
	 */
	function _modifyBaseInfo(){

		$this->objmember->modifyMember($this->_input,$_SESSION['s_login']['id']);
		$this->redirectPath("succ","/member/own_member.php","您修改个人信息成功！");
	}
	/**
	 * 会员修改邮箱
	 *
	 */
	function _getMemberEmail(){
		/**
		 * 得到会员资料
		 */
		$condition['id'] = $_SESSION['s_login']['id'];
		$member_array = $this->objmember->getMemberInfo($condition);
		$this->output('member_array',$member_array);
		$this->showpage("own_member.email");
	}

	/**
	 * 修改邮箱，保存到数据库中
	 *
	 */
	function _saveMemberEmail(){
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}
		/**
		 * 验证提交的表单
		 */
		$this->objvalidate->setValidate(array("input"=>$this->_input['txtemail'],"require"=>"true","validator"=>"Email","message"=>$this->_lang['errMEmail_Wrong']));    //请输入正确格式的email!
		//print_r($this->objvalidate->validateparam);
		$error = $this->objvalidate->validate();
		if($error != ""){
			$this->redirectPath("error","",$error);
		}else{
			$this->objmember->modifyMember($this->_input,$_SESSION['s_login']['id'],"email");
			$this->redirectPath("succ","/member/own_member.php?action=email","您修改邮件信息成功！");
		}
	}

	/**
	 * 修改密码，保存到数据库中
	 *
	 */
	function _saveMemberPassword(){
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}
		/**
		 * 验证注册信息
		 */
		$this->objvalidate->setValidate(array("input"=>$this->_input['txtoldpassword'],"require"=>"true","message"=>$this->_lang['alertEnterPassword']));
		$this->objvalidate->setValidate(array("input"=>$this->_input['txtPassword'],"require"=>"true","validator"=>"Length","min"=>6,"max"=>16,"message"=>$this->_lang['alertEnterPassword']));    //密码由6-16个字符组成，请使用英文字母加数字或符号的组合密码，不能单独使用英文字母、数字或符号作为您的密码。
		$this->objvalidate->setValidate(array("input"=>$this->_input['txtPassword'],"require"=>"true","validator"=>"Compare","operator"=>"==","to"=>$this->_input['txtrePassword'],"message"=>$this->_lang['errMRePassword_Wrong']));   //两次输入的密码不相同!
		$error = $this->objvalidate->validate();
		if ($error != "" ){
			$this->redirectPath("error","",$error);
		}else{
			$condition['id'] = $_SESSION['s_login']['id'];
			$member_array = $this->objmember->checkMemberExist($condition,'3');
			if(md5($this->_input['txtoldpassword']) == $member_array['password']){
				$this->objmember->modifyMember($this->_input,$_SESSION['s_login']['id'],"password");
				/**
		         * 创建网站邮件发送内容信息对象
		         */
				if (!is_object($this->objcontent)){
					require_once("mailcontent.class.php");
					$this->objcontent = new MailContentClass();
				}
				$content = $this->objcontent->getMailContent("modipass");   //获得发信内容
				if ($content['ifopen']){

					/**
		             * 创建发信对象
		             */
					if (!is_object($this->objmail)){
						require_once("sendmail.class.php");
						//$this->objmail = new SendMail($this->_configinfo['websit']['smtpserver'],$this->_configinfo['websit']['smtpprot'],true,$this->_configinfo['websit']['smtpuser'],$this->_configinfo['websit']['smtppass']);
					}
					$param = array(
					'website'=>$this->_configinfo['websit']['site_title'],
					'site_url'=>$this->_configinfo['websit']['site_url'],
					'username'=>$this->_input['txtloginname'],
					'newpass'=>$this->_input['txtPassword']
					);
					$content['content'] = Common::replaceMailContent($param,$content['content']);   //将发信内容的变量换为值
					$content['title'] = Common::replaceMailContent($param,$content['title']);       //将发信标题的变量换为值
					echo $content['title'] . $content['content'];
					//$this->objmail->send($this->_input['txtemail'],$this->_configinfo['websit']['smtpemail'],$this->_configinfo['websit']['site_name'],$content['title'],$content['content']);   //发信
				}
				$this->redirectPath("succ","/member/own_member.php?action=password","您修改密码信息成功！");
			}else{
				$this->redirectPath("error","","密码填写错误！");
			}
		}
	}
}
$member = new OwnMemberManage();
$member->main();
unset($member);
?>